package models

import (
	"doctor-srv/basic/config"
	"gorm.io/gorm"
)

// 医生表
type Doctor struct {
	gorm.Model
	Name   string `json:"name" gorm:"type:varchar(30);comment:'医生姓名'"`
	Lever  string `json:"lever" gorm:"type:varchar(50);comment:'医生级别'"`
	Depart string `json:"depart" gorm:"type:varchar(30);comment:'科室'"`
	Desc   string `json:"desc" gorm:"type:varchar(300);comment:'描述'"`
	Image  string `json:"image" gorm:"type:varchar(300);comment:'图片'"`
	Number int    `json:"number" gorm:"type:int;comment:'排班余额'"`
	Status int    `json:"status" gorm:"type:int;comment:'状态 1-无排班 2-已排班'"`
}

func (d *Doctor) TableName() string {
	return "doctor"
}

func (d *Doctor) AddDoctor() error {
	return config.DB.Create(&d).Error
}

func (d *Doctor) GetDoctor(id int) error {
	return config.DB.Model(&Doctor{}).Where("id = ?", id).Limit(1).Find(&d).Error
}

// 扣减余额
func (d *Doctor) DeleteNumber(id int) error {
	return config.DB.Model(&Doctor{}).Where("id = ?", id).Update("number", gorm.Expr("number - ?", 1)).Find(&d).Error
}
